package com.eBook.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.ResponseBody;

import com.eBook.entity.Book;
import com.eBook.entity.Comment;
import com.eBook.entity.Test;
import com.eBook.entity.User;
import com.eBook.service.TestService;

@Controller
@RequestMapping(value = "/test")
public class TestController {
	@Autowired
	private TestService tService;
	
	@RequestMapping(value = "/",method = RequestMethod.GET)
	@ResponseBody
	public List<Test> getAllTests(){
		return tService.findAllTests();
	}
	@RequestMapping(value = "/{account}")
	@ResponseBody
	public User getUserByAccount(@PathVariable("bookId")String account){
		return tService.findUserByAccount(account);
	}
	@RequestMapping(value = "/{bookId}")
	@ResponseBody
	public List<Comment> findAllCommentsByBookId(@PathVariable("bookId")int bookId){
		return tService.findAllCommentByBookId(bookId);
	}
	@RequestMapping(value = "/",method = RequestMethod.POST)
	@ResponseBody
	public String addComment(int bookId,int userId,String content){
		Comment comment = new Comment(bookId,userId,content);
		tService.addComment(comment);
		return "评论成功！";
	}
	@RequestMapping(value = "/{typeId}")
	@ResponseBody
	public List<Book> findAllBooks(@PathVariable("typeId") int typeId){
		return tService.findAllBooksByTypeId(typeId);
	}
}
